//
//  AlertController.swift
//  CooperSwift
//
//  Created by 计海峰 on 2022/9/24.
//

import Foundation
public extension UIAlertController {
    class func confirmAlertView(title: String?, message: String?, cancelTitle: String = "取消", confirmTitle: String = "确定", cancel: (() -> Void)? = nil,  confirm: @escaping () -> Void) -> UIAlertController {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel, handler: { action in
            guard let cancel = cancel else { return }
            cancel()
        }))
        alert.addAction(UIAlertAction(title: confirmTitle, style: .default) { action in
            confirm()
        })
        return alert
    }
    
    class func singleAlertView(title: String?, message: String?, confirmTitle: String = "确定", confirm: @escaping () -> Void) -> UIAlertController {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: confirmTitle, style: .default) { action in
            confirm()
        })
        return alert
    }

}
